<?php 
	
	session_start();
		
	header("Content-Type: text/html;charset=utf-8");

	include ("DB.class.php"); 

	$oDBUtil = new dbUtil("localhost", "root", "456789", "mysqlstudy");
	$oDBUtil->setMaxTry('connect',5);//最多连接5次
	$oDBUtil->setMaxTry('query',3);//最多查询3次
	if(!$oDBUtil->connect()){
		echo "连接失败";
		exit();
	}
	$oDBUtil->setCharset('utf8');  //设置字符集编码

	$username = $_POST["username"]; //获取输入的用户名
	$pwd = $_POST["password"];  //获取输入的密码
	$code = $_POST["code"];  //获取输入的验证码

	$code = strtolower($code); //将获取到的验证码转为小写
	$pwd = md5($pwd); //将获取的密码进行md5加密

	$sessionCode = $_SESSION["code"];  //获取保存在session中的code值

	if($code != $sessionCode){
		$errArr = array("status"=>"no","msg"=>"验证码不正确！");
		echo json_encode($errArr);
	}else{
		$sql = "SELECT * FROM tp_user_info WHERE username='" . $username . "' and password='" . $pwd ."'";

		if(! $oDBUtil->query($sql)){   //如果查询失败
			echo "查询失败";
			exit();
		}

		$oResult = $oDBUtil->getResult();
		$obj = $oResult->fetch_assoc();

		if($obj){
			$okArr = array("status"=>"yes","msg"=>"登录成功！");
			echo json_encode($okArr);
		}else{
			$errArr = array("status"=>"no","msg"=>"用户名或密码不正确！");
			echo json_encode($errArr);
		}
	}




	
?>